<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>promise</title>
</head>
<body>
    

    <script>
        // promise 并不是一个新鲜的产物，不过是为了解决之前的一个回调函数嵌套的问题的

        let checkLogin = function () {
            return new Promise((resolve,reject)=>{
                // let flag = document.cookie.indexof("uerId")>-1?true:false;
                let flag = true;
                if(flag){
                    resolve({
                        status: 0,
                        result: true
                    });
                }else{
                    reject('error');
                }
            });
        }
        
        let getUserInfo = () => {
            let userInfo = {
                userId: '100123'
            }

            return new Promise((resolve)=>{
                resolve(userInfo);
            });
        }

        checkLogin().then((res)=>{
            if(res.status === 0){
                console.log("login success");
            }

            return getUserInfo();
        }).catch((res)=>{
            console.log('error')
        }).then((res2)=>{
            console.log(res2.userId);
        });



        
    </script>
</body>
</html>